package com.ruoyi.mqtt.service;


import com.ruoyi.mqtt.config.MqttClientConnect;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;

@Component
public class SubscribeService {

    @Autowired
    MqttClientConnect mqttClientConnect;

    @Autowired
    MqttMessageCallback1 mqttMessageCallback1;

    @PostConstruct
    public void subscribe(){
        try {
            //# 表示多层
            //+ 表示一层
            //订阅的主题
            mqttClientConnect.subscribe("mqtt/");
            mqttClientConnect.setCallback(mqttMessageCallback1);//消息处理类
        } catch (MqttException e) {
            e.printStackTrace();
        }
    }
}
